package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author kabuda
 * @create 2022-08-19 10:51
 */
@Service(interfaceClass = OrderSettingService.class)
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    OrderSettingDao orderSettingDao;
    @Override
    public void add(List<OrderSetting> orderSettings) {
        if(orderSettings!=null){
            for (OrderSetting orderSetting:orderSettings){
              Long count= orderSettingDao.selectCountByDate(orderSetting.getOrderDate());
              if(count>0){
                  orderSettingDao.edit(orderSetting);
              }else{
                  orderSettingDao.add(orderSetting);
              }
            }
        }
    }

    @Override
    public List<OrderSetting> getOrderSettingByMonth(String date) {
       return orderSettingDao.getOrderSettingByMonth(date);
    }

    @Override
    public void editNumberByDate(OrderSetting orderSetting) {
        Date orderDate = orderSetting.getOrderDate();
        Long aLong = orderSettingDao.selectCountByDate(orderDate);
        if(aLong>0){
            orderSettingDao.edit(orderSetting);
        }else{
            orderSettingDao.add(orderSetting);
        }

    }
}
